<!--
    	作者：zyc
    	时间：2018-10-17
    	描述：实物对账单列表
    -->

<template>
	<div class="m-view-goodAccountList m-window">
		<div class="m-agTable m-bottom">
			<ag-grid-vue  
				class="m-agTableContent ag-theme-balham" 
				:gridOptions="phyGridOptions" 
				:columnDefs="columnDefs" 
				:rowData="rowData"  
				v-loading="loading" 
				rowSelection="single"></ag-grid-vue>
		</div>
	</div>
</template>

<script>
	import _Api from "@/api";
	import localeText from "@/i18n/agGridText";
	
	export default{
		data(){
			return{
				rowData:[],
				columnDefs:[],
				loading:false
			}
		},
		beforeMount(){
			var colors = ['#FFFF00'];
			this.phyGridOptions = {
				context: {
					componentParent: this
				},
        	    enableColResize: true,
				localeText: localeText,
				enableCellChangeFlash: true,
				getRowStyle:function(params){
					if(params.data.retFlag == "1" && params.data.billState == "1"){
						return{
							backgroundColor: colors[0]
						}
					}else{
						return{
							backgroundColor:null
						}
					}
					
				},
				suppressRowClickSelection: true
			};
			this.columnDefs = [
			{	headerName:"实物对账单号",field:"gooAccNo",width:150,checkboxSelection: true,headerCheckboxSelection: true,headerCheckboxSelectionFilteredOnly:true},
			{	headerName:"公司",field:"companyName",width:200},
			{	headerName:"供应商",field:"supplierName",width:200},
			{	headerName:"对账金额",field:"amount",width:100},
			{	headerName:"申请人",field:"creator",width:100},//,width:450
			{	headerName:"申请时间",field:"createDate",width:150},//,width:450
			{	headerName:"确认人",field:"confirmer",width:100},
			{	headerName:"确认时间",field:"",width:150},
//			{	headerName:"申请日期",field:"createDate",cellRenderer:function(params){
//					if(params.value){
//						return new Date(Date.parse(params.value.replace(/-/g,"/"))).Format("yyyy-MM-dd");
//					}
//				}
//			},
			{	
                headerName:"单据状态",
                field:"billState",
                width:100,
                cellRenderer:function(params){
					if(params.value =="1")
						return '<span class="ag-icon">未确认</span>';
					else if(params.value =="2")
						return '<span class="ag-icon">已确认</span>';
				}
            }
            ]
            let tips = ['companyName','supplierName','matName','creator']
            this.columnDefs.forEach(col => {
                if(tips.indexOf(col.field)>-1){
                    col.tooltipField = col.field
                }
            })
		},
		methods:{
			getDataRows(msg){
				this.phyGridOptions.api.setRowData(msg);
				
				let allColumnIds = [];
				this.phyGridOptions.columnApi.getAllColumns().forEach(function(column) {
					allColumnIds.push(column.colId);
				});
				
				this.phyGridOptions.columnApi.autoSizeColumns(allColumnIds);
			},
			//删除实物对账单
			getSelectedRow(){
				var row  = this.phyGridOptions.api.getSelectedRows();
				if(row.length <= 0 ){
					this.$alert("提示：请选择需要删除的数据",{
						showClose:false,
						confirmButtonText:"确定",
						customClass:"alertPrompt"
					});
					return;
				}
				var that = this;
				this.$confirm("是否确认删除该数据？","消息提示",{
					confirmButtonText:"确定",
					cancelButtonText:"取消",
					distinguishCancelAndClose:true
				}).then(()=>{
					var id = '';
					for(var i = 0;i<row.length;i++){
						id += row[i].id + ',';
					}
					id = id.substr(0,id.length-1);
					var obj ={
						dataType:1,
						id:id,
						modifyer:this.$global.user.loginName,
						modifyerId:this.$global.user.id,
						state:1
					};
					_Api.delAccountListSelectedInfo(obj).then(function(response){
						var data = response.data;
						if(data.code == "1")
						{
	                        that.$message({
	                            message: "操作成功",
	                            type: "success"
	                        });
	                        that.phyGridOptions.api.updateRowData({
	                        	remove: row
	                        });
						}else{
	                        that.$alert(data.info, {
	                            showClose: false,
	                            confirmButton: "确定",
	                            customClass: "alertFailure"
	                        });
						}
					}).catch((err)=>{
						that.$alert(err.data.message, {
							showClose: false,
							confirmButton: "确定",
							customClass: "alertFailure"
						});
					})
				})
			},
			setClickValue(value){
				this.$emit('getClickValue',value);
			}
		},
		mounted(){
			//？
//			var userTypeId = this.$global.user.userTypeId;
//			if(userTypeId){
//				//供应商
//				if(userTypeId == 4){
//					this.columnDefs.splice(2,1);
//					this.columnDefs.splice(3,1);
//				}else{
//					this.columnDefs.splice(1,1);
//					this.columnDefs.splice(2,1);
//				}
//			}
		}
	
	}
</script>
